#include <typeinfo>
#include <utility>
#include <assert.h>
class Any
{
private:
    /*父类holder，用到多态*/
    class holder
    {
    public:
        ~holder() {}
        virtual holder *clone() = 0;
        virtual std::type_info type() = 0;
    };
    template <class T>
    class placeholder : holder
    {
    public:
        virtual holder *clone() override
        {
            return new placeholder(_val);
        }
        virtual std::type_info type() override
        {
            return typeid(T);
        }
        placeholder(const T &val) : _val(val) {}
        T &Getval()
        {
            return _val;
        }

    private:
        T _val;
    };
    holder *_content;
    Any &swap(Any &other)
    {
        std::swap(_content, other._content);
        return *this;
    }

public:
    Any() : _content(nullptr) {}
    template <class T>
    Any(const T &val) : _content(new placeholder<T>(val)) {}
    Any(const Any &other) : _content(other._content == nullptr ? nullptr : other._content->clone()) {}
    ~Any() { delete _content; }
    template <class T>
    T *get()
    {
        assert(_content->type() == typeid(T));
        return &((placeholder<T> *)_content->Getval());
    }
    template <class T>
    Any &operator=(const T &val)
    {
        return Any(val).swap(*this);
    }
    Any &operator=(const Any &other)
    {
        return Any(other).swap(*this);
    }
};

int main(int argc, char *argv)
{
    return 0;
}